package com.incar.chuxing.activity.certification;

import android.content.Context;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.incar.chuxing.R;
import com.incar.chuxing.api.ApiStore;
import com.incar.chuxing.api.UrlContainer;
import com.incar.chuxing.application.MyApplication;
import com.incar.chuxing.base.BaseActivity;
import com.incar.chuxing.bean.UserCarInforBean;
import com.incar.chuxing.utils.AppManager;
import com.incar.chuxing.utils.Logger;
import com.incar.chuxing.utils.ToastUtils;

import butterknife.BindView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 身份认证通过
 */
public class CertifyCardOkActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.tv_cartype)
    TextView tvCartype;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_starttime)
    TextView tvStarttime;
    @BindView(R.id.tv_endtime)
    TextView tvEndtime;
    private Context mContext = this;


    @Override
    public int getLayoutId() {
        return R.layout.activity_card_ok;
    }

    @Override
    public void initView() {
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppManager.getAppManager().finishActivity();
            }
        });
        getUserCarInfo();
    }


    //认证信息
    private void getUserCarInfo() {
        showLoadingDialog();
        ApiStore.getInstance().getApiService(UrlContainer.Request.BASE_GATE_URL).getUserCarInfo(((MyApplication) getApplication()).getRequestFieldMap()).enqueue(new Callback<UserCarInforBean>() {
            @Override
            public void onResponse(Call<UserCarInforBean> call, Response<UserCarInforBean> response) {
                dismissLoadingDialog();
                if (response.isSuccessful() && response.body() != null) {
                    if (response.body().getStatus() == 200) {
                        UserCarInforBean carInforBean = response.body();
                        tvName.setText(carInforBean.getAttachment().getFullName());
                        tvCartype.setText(carInforBean.getAttachment().getQuasiDrivingType());
                        tvStarttime.setText(carInforBean.getAttachment().getLicensingOfTime());
                        tvEndtime.setText(carInforBean.getAttachment().getDrivingLicencePeriodOfValidity());
                    } else {
                        ToastUtils.makeText(mContext, response.body().getMessage(), ToastUtils.LENGTH_SHORT).show();
                    }
                } else {
                    ToastUtils.makeText(mContext, getResources().getString(R.string.serverError), ToastUtils.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(Call<UserCarInforBean> call, Throwable t) {
                dismissLoadingDialog();
                ToastUtils.makeText(mContext, getResources().getString(R.string.badNetwork), ToastUtils.LENGTH_SHORT).show();
                Logger.d("neterror", "011" + t);
            }
        });

    }

    @Override
    public void onBackPressed() {
        AppManager.getAppManager().finishActivity();
    }
}
